<template>
    <div>
        <h1>登录</h1>
        <br>
        <input type="text" v-model="name" placeholder="请输入名字">
        <br>
        <input type="password" v-model="password" placeholder="请输入密码">
        <br>
        <button @click="login">登录</button>
    </div>
</template>

<script>
export default {
    data:function(){
        return{
            name:'',
            password:''
        }
    },
    methods:{
        login:function(){
            let formData = new FormData();
            formData.append('name',this.name);
            formData.append('password',this.password)

            this.axios({
                url:"http://127.0.0.1:8000/login/",
                method:'post',
                data:formData
            }).then((res)=>{
                if(res.data.code==200){
                    alert(res.data.message);
                    sessionStorage.setItem('uid',res.data.uid);
                    sessionStorage.setItem('coursr', JSON.stringify(res.data.course))
                    // sessionStorage.setItem('coursr', res.data.course)
                    this.$router.push({path:"/show"})
                }else{
                    alert(res.data.message)
                }
            })
        }
    }
}
</script>
